<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

mm_showMyFileName( __FILE__ );
require_once( CLASSPATH . 'BK_checkout.php');
require_once( CLASSPATH."payment/ps_baokim.cfg.php");

if(isset($_GET['checksum']) && !empty($_GET['checksum']))
{
	$array		=	array(
		'created_on'			=>	'',
		'customer_email'		=> '',
		'customer_name'		=> '',
		'customer_phone'		=> '',
		'fee_amount'			=> '',
		'merchant_email'		=> '',
		'merchant_id'			=> '',
		'merchant_name'		=> '',
		'merchant_phone'		=> '',
		'order_id'				=> '',
		'payment_type'			=> '',
		'total_amount'			=> '',
		'transaction_id'		=> '',
		'created_on'			=> '',
		'transaction_status'	=> '',
		'checksum'				=> ''
	);
	
	foreach($array as $key=>$value){
		$array[$key]	=	isset($_GET[$key]) ? $_GET[$key] : '';
	}

	$bk = new BaoKimPayment();
	$check = $bk->verifyResponseUrl($array);
	if($check === false)
	{
		#Tham số gửi về không hợp lệ, có sự can thiệp từ bên ngoài
		echo 'Kết quả thanh toán không hợp lệ';
	}
	else
	{
		if($error_text != '')
		{
			#Có lỗi trong quá trình thanh toán
			echo 'Có lỗi: '.$error_text.'!';
		}
		else
		{
			#Thanh toán thành công
			echo 'Thanh toán thành công!';
		}
	}
}
else #Gửi thông tin
{


	$bk = new BaoKimPayment();
	$bk->merchant_id = merchant_id;
	$bk->secure_pass = baokim_secure_pass;
	
	$order_description = @$_POST['customer_note'];
	$order_id = 'DH:'.date('d-m-Y',time());
	$total_amount = intval(@$_POST['total_amount']);
	$shipping_fee	=	'0';
	$tax_fee			=	'0';
	$business		= business;	
	$url_success 	= url_success;
	$url_detail 	= url_detail;
	$url_cancel 	= url_cancel;
	
	$url = $bk->createRequestUrl($order_id, $business,$total_amount, $shipping_fee, $tax_fee, $order_description, $url_success, $url_cancel, $url_detail);	
	
/*	echo $order_id . '</br>';
	echo $total_amount . '</br>';
	echo $business . '</br>';
	echo merchant_id . '</br>';
	echo baokim_secure_pass . '</br>';
	die();*/
	
	vmRedirect( $url );
	exit();
}
?>